package utils;

import com.bit.utils.FileUtils;

import java.io.IOException;

public class AnalyzingBookIdMax{
    public void storeBookIdMax(int bookIdMax, String filename)throws IOException {
        StringBuilder jsonBId = new StringBuilder();
        jsonBId.append(bookIdMax);
        FileUtils.writeFile(jsonBId.toString(), filename);
    }

    public int loadBookIdMax(String filename)throws IOException{
        String sBookId = FileUtils.readFile(filename);
        StringBuilder json = new StringBuilder();
        String bookId = json.append(sBookId).toString();
        String newBookId = bookId.replaceAll("\n", "");

        if(newBookId == null || newBookId.isEmpty()){
            return -1;
        }else {
            int bookIdMax = Integer.parseInt(newBookId);
            return bookIdMax;
        }
    }
}
